package com.example.demo.mapper;/**
 * ClassName: Subscribe
 * Package: com.example.demo.mapper
 * Description:
 *
 * @Author 理理
 * @Create 2024/11/16 19:15
 * @Version 1.0
 */

import com.example.demo.entity.Subscribe;
import com.example.demo.entity.TimeSlotAvailability;
import org.apache.ibatis.annotations.*;

import java.sql.Date;
import java.util.List;

/**
 *
 *@title: Subscribe
 *@Author: Tangerine
 *@Date: 2024/11/16 19:15
 *@version 1.0
 */
@Mapper
public interface SubscribeMapper {
    //查询所有数据
    @Select("select * from subscribe")
    List<Subscribe> findAll();

    //分页查询数据,多个参数需要增加注解标识指定参数
    @Select("select * from subscribe limit #{pageNum},#{pageSize}")
    List<Subscribe> selectPage(@Param("pageNum") Integer pageNum,@Param("pageSize") Integer pageSize);

    //查询记录总数
    @Select("select count(*) from subscribe")
    Integer selectTotal();

    //新增一条预约
    @Insert("insert into subscribe(studentNumber,classes_name,type,time,labType,number,state,result,date) " +
            "VALUES(#{studentNumber},#{classes_name},#{type},#{time},#{labType},#{number},#{state},#{result},#{date});")
    int insert(Subscribe subscribe);

    //更新一条预约
    @Update("update subscribe set studentNumber=#{studentNumber},classes_name=#{classes_name},type=#{type}," +
            "time=#{time},labType=#{labType},number=#{number},state=#{state},result=#{result},date=#{date} where id=#{id}")
    int update(Subscribe subscribe);


    //删除一条预约
    @Delete("delete from subscribe where id=#{id}")
    int deleteById(@Param("id") Integer id);


    //查询不同类型的所有数据
    @Select("select * from subscribe where labType=#{labType}")
    List<Subscribe> labTypeSelect(@Param("labType") int labType);

    //查询不同类型的所有数据,分页显示
    @Select("select * from subscribe where labType=#{labType} limit #{pageNum},#{pageSize}")
    List<Subscribe> labTypeSelectPage(@Param("labType") int labType,@Param("pageNum") Integer pageNum,@Param("pageSize") Integer pageSize);

    //分类查询
    @Select("select * from subscribe where type=#{type}")
    List<Subscribe> typeSelect(@Param("type") String type);

    @Select("select * from subscribe where state=#{state}")
    List<Subscribe> stateSelect(@Param("state") String state);

    //历史预约全部
    @Select("select * from subscribe where studentNumber=#{studentNumber}")
    List<Subscribe> findHistory(@Param("studentNumber") String studentNumber);
    //历史预约分页
    @Select("select * from subscribe where studentNumber=#{studentNumber} limit #{pageNum},#{pageSize}")
    List<Subscribe> findHistoryPage(@Param("studentNumber") String studentNumber,@Param("pageNum") Integer pageNum,@Param("pageSize") Integer pageSize);

    //查找用户预约成功的记录是否已完成，并修改状态
    @Update("update subscribe set state='预约完成' where id=#{id} and state='预约成功'")
    int alterState(@Param("id") Integer id);

    //根据管理员姓名找所有预约记录里他所管理的实验室
    @Select("select subscribe.* from subscribe join classes on subscribe.classes_name=classes.name where classes.manager=#{manager}")
    List<Subscribe> getAdminClasses(@Param("manager") String manager);
}
